import {
  getCollectorList,
  getElectricMeterList,
  getWaterMeterList,
  getSupplierList,
  saveCollector,
  removeCollector,
  saveElectricMeter,
  removeElectricMeter,
  getCollectorNoList,
  saveWaterMeter,
  removeWaterMeter,
  resetWater,
  resetElectric,
  readElectricMeter,
  pullElectricMeter,
  readWaterMeter,
  pullWaterMeter,
  getContectPrice,
  getElectricOpenAcount
} from '@/api/waterElectricMeter'
export default {
  namespaced: true, // 封闭
  state: {},
  mutations: {},
  getters: {},
  actions: {

    // 电费管理 保存开户设置
    async fetchElectricOpenAcount(context, payload) {
      try {
        const { data } = await getElectricOpenAcount(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 电表 开户 获取 合同 的价格
    async fetchContectPrice(context, payload) {
      const { openStallId } = payload
      try {
        const { data } = await getContectPrice(openStallId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取采集器列表
    async fetchCollectorList(context, payload) {
      const { collectorNo } = payload
      try {
        const { data } = await getCollectorList(collectorNo)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取电表
    async fetchElectricMeterList(context, payload) {
      const { searchName } = payload
      try {
        const { data } = await getElectricMeterList(searchName)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取水表
    async fetchWaterMeterList(context, payload) {
      const { searchName } = payload
      try {
        const { data } = await getWaterMeterList(searchName)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取供应商列表
    async fetchSupplierList(context, payload) {
      try {
        const { data } = await getSupplierList()
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 保存新增的采集器
    async fetchSaveCollector(context, payload) {
      try {
        const { data } = await saveCollector(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 删除 采集器
    async fetchRemoveCollector(context, payload) {
      try {
        return await removeCollector(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 保存新增的电表
    async fetchSaveElectricMeter(context, payload) {
      try {
        const { data } = await saveElectricMeter(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 删除 电表
    async fetchRemoveElectricMeter(context, payload) {
      try {
        return await removeElectricMeter(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 清零 电表
    async fetchResetElectric(context, payload) {
      try {
        return await resetElectric(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 获取采集器列表
    async fetchCollectorNoList(context, payload) {
      try {
        const { data } = await getCollectorNoList()
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 保存新增的水表
    async fetchSaveWaterMeter(context, payload) {
      try {
        const { data } = await saveWaterMeter(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 删除 水表
    async fetchRemoveWaterMeter(context, payload) {
      try {
        return await removeWaterMeter(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 清零 水表
    async fetchResetWater(context, payload) {
      try {
        return await resetWater(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 抄电表
    async fetchReadElectricMeter(context, payload) {
      try {
        return await readElectricMeter(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 电表 开阀
    async fetchPullElectricMeter(context, payload) {
      const {
        id, controlStatus
      } = payload
      try {
        return await pullElectricMeter(id, controlStatus)
      } catch (err) {
        console.log(err)
      }
    },
    // 抄水表
    async fetchReadWaterMeter(context, payload) {
      try {
        return await readWaterMeter(payload.id)
      } catch (err) {
        console.log(err)
      }
    },
    // 水表 开关阀
    async fetchPullWaterMeter(context, payload) {
      const {
        id, controlStatus
      } = payload
      try {
        return await pullWaterMeter(id, controlStatus)
      } catch (err) {
        console.log(err)
      }
    }
  }
}
